/**
 * @program: LeetCode
 * @description: LeetCode : 45. 跳跃游戏 II
 * @author: WXY
 * @create: 2023-01-20 16:31
 * @Version 1.0
 **/
public class Num045_jump {
    public static int jump(int[] arr) {
        int longestDistance = 0;  //最远的覆盖距离
        int end = 0;  //当前覆盖的最远距离
        int ans = 0; //步数
        for (int i = 0; i < arr.length; i++) {
            longestDistance = Math.max(longestDistance, i + arr[i]);
            if (i >= end) {
                end = longestDistance;
                ans++;
            }
        }
        return ans;
    }
}
